// 导入sequelize实例
const { sequelize } = require('../config/db');
const { DataTypes } = require('sequelize');

// 定义预约模型
const Appointment = sequelize.define('Appointment', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  department: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '科室名称'
  },
  doctor: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '医生姓名'
  },
  doctor_title: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '医生职称'
  },
  date: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '预约日期'
  },
  time: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '预约时间段'
  },
  patient_name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '就诊人姓名'
  },
  patient_phone: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '就诊人身份证号'
  },
  clinic_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '诊所ID'
  },
  doctor_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '医生ID'
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '用户ID'
  },
  status: {
    type: DataTypes.STRING,
    allowNull: false,
    defaultValue: 'pending',
    comment: '预约状态（pending：待确认，confirmed：已确认，cancelled：已取消）'
  },
  created_at: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    comment: '更新时间'
  }
}, {
  tableName: 'appointments',
  comment: '预约表',
  timestamps: false,
  indexes: [
]
});

module.exports = { Appointment };